package com.zhuoshi.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhuoshi.entity.AuthorityCustom;
import com.zhuoshi.service.AuthorityService;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("authority")
public class AuthorityController {
	@Autowired
	private AuthorityService authorityService;
	
	@RequestMapping("selectMenu")
	public void  selectMenu(HttpServletResponse response) throws IOException{
		List<AuthorityCustom> menuList= authorityService.selectChildrenMenu(0);
		JSONObject jsonObject = new JSONObject();
		response.setCharacterEncoding("utf-8");
		jsonObject.put("menuList", menuList);
		response.getWriter().println(jsonObject.toString());
	}
	
	@RequestMapping("selectTreeMenu")
	public void  selectTreeMenu(Integer rid,AuthorityCustom authorityCustom,HttpServletResponse response) throws IOException{		
		List<AuthorityCustom> menuList= authorityService.selectMenu(authorityCustom);
		System.out.println(authorityCustom.getRid());
		System.out.println(authorityCustom.getPid());
		JSONObject jsonObject = new JSONObject();
		response.setCharacterEncoding("utf-8");
		jsonObject.put("menuList", menuList);
		response.getWriter().println(jsonObject.toString());
	}
}
